/*
 * @Author: jianglijun1004 
 * @Date: 2020-03-10 03:48:42 
 * @Last Modified by: jianglijun
 * @Last Modified time: 2020-03-13 02:02:05
 */
// const Token = require('../app/database/schema/token')
const mongoose = require('mongoose')
const Wechat = require('../wechat-lib')
const WechatOauth = require('../wechat-lib/oauth')
const config = require('../config/config')
const wechatConfig = {
  wechat: {
    appID: config.wx.appID,
    appSecret: config.wx.appSecret,
    token: config.wx.token,
    getAccessToken: async () => {
      const data = await mongoose.model('Token').getAccessToken();
      return data;
    },
    saveAccessToken: async (data) => {
      await mongoose.model('Token').saveAccessToken(data);
    },
    getOAuthToken: async (name) => {
      const data = await mongoose.model('OAuth').getOAthToken(name);
      return data;
    },
    saveOAuthToken: async (data) => {
      await mongoose.model('OAuth').saveOAthToken(data);
    },
    getTicket: async () => {
      const data = await mongoose.model('Ticket').getTicket();
      return data;
    },
    saveTicket: async (data) => {
      await mongoose.model('Ticket').saveTicket(data);
    }
  }
};
exports.getWechat = () => new Wechat(wechatConfig.wechat)
exports.getOAuth = () => new WechatOauth(wechatConfig.wechat)
